From 6da8f5e755f02ca3c3fb2c625da78612cff7775d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 20 Dec 2017 03:22:22 +0100 Subject: [PATCH] extensions-gggl: clamp when converting float to 16bit Improve the quality of a conversion that was picked in error for bug #790658 --- extensions/gggl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/gggl.c b/extensions/gggl.c index cf83988..625d730 100644 --- a/extensions/gggl.c +++ b/extensions/gggl.c @@ -543,7 +543,12 @@ conv_rgbaF_rgb16 (const Babl *conversion,unsigned char *src, unsigned char *dst, for (c = 0; c < 3; c++) { - *(unsigned short *) dst = lrint ((*(float *) src) * 65535.0); + if ((*(float *) src) >= 1.0) + *(unsigned short *) dst = 65535; + else if ((*(float *) src) <=0) + *(unsigned short *) dst = 0; + else + *(unsigned short *) dst = lrint ((*(float *) src) * 65535.0); dst += 2; src += 4; } -- 2.30.2